package com.ruoyi.business.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.business.config.ALiBaBaIdCard;
import com.ruoyi.business.config.AliBaBaIdentity;
import com.ruoyi.business.response.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.TbBusinessMapper;
import com.ruoyi.business.domain.TbBusiness;
import com.ruoyi.business.service.ITbBusinessService;

/**
 * 商家Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-02-01
 */
@Service
public class TbBusinessServiceImpl implements ITbBusinessService 
{
    @Autowired
    private TbBusinessMapper tbBusinessMapper;

    /**
     * 查询商家
     * 
     * @param id 商家主键
     * @return 商家
     */
    @Override
    public TbBusiness selectTbBusinessById(Long id)
    {
        return tbBusinessMapper.selectTbBusinessById(id);
    }

    /**
     * 查询商家列表
     * 
     * @param tbBusiness 商家
     * @return 商家
     */
    @Override
    public List<TbBusiness> selectTbBusinessList(TbBusiness tbBusiness)
    {
        return tbBusinessMapper.selectTbBusinessList(tbBusiness);
    }

    /**
     * 新增商家
     * 
     * @param tbBusiness 商家
     * @return 结果
     */
    @Override
    public int insertTbBusiness(TbBusiness tbBusiness)
    {

        return tbBusinessMapper.insertTbBusiness(tbBusiness);
    }

    /**
     * 修改商家
     * 
     * @param tbBusiness 商家
     * @return 结果
     */
    @Override
    public int updateTbBusiness(TbBusiness tbBusiness)
    {
        return tbBusinessMapper.updateTbBusiness(tbBusiness);
    }

    /**
     * 批量删除商家
     * 
     * @param ids 需要删除的商家主键
     * @return 结果
     */
    @Override
    public int deleteTbBusinessByIds(Long[] ids)
    {
        return tbBusinessMapper.deleteTbBusinessByIds(ids);
    }

    /**
     * 删除商家信息
     * 
     * @param id 商家主键
     * @return 结果
     */
    @Override
    public int deleteTbBusinessById(Long id)
    {
        return tbBusinessMapper.deleteTbBusinessById(id);
    }

//    /**
//     * 调用阿里接口验证身份证
//     * @param tbBusiness
//     * @return
//     */
//    @Override
//    public Result checkId(TbBusiness tbBusiness) {
//        //调用阿里接口
//        AliBaBaIdentity aliBaBaIdentity = new AliBaBaIdentity();
//        //设置返回值
//        Map<String, Object> resultMap = new HashMap<>();
//        try {
//            resultMap = aliBaBaIdentity.Identity(tbBusiness.getBusinessName(), tbBusiness.getBusinessIdcard());
//        }catch (Exception e){
//            e.printStackTrace();
//
//        }
//        //取出状态码
//        Integer code = (Integer) resultMap.get("code");
//        if(code!=200){
//            return new Result(false,"0","执行失败");
//        }
//        return new Result(true,"1","执行成功");
//    }
//
//    /**
//     * 对银行卡信息进行校验
//     * @param tbBusiness
//     * @return
//     */
//    @Override
//    public Result checkBankId(TbBusiness tbBusiness) {
//        //调用阿里接口
//        ALiBaBaIdCard aLiBaBaIdCard = new ALiBaBaIdCard();
//        //设置返回值
//        String result = null;
//        try {
//            result = aLiBaBaIdCard.checkCard(tbBusiness.getBusinessBankcard(),
//                    tbBusiness.getBusinessName(),
//                    tbBusiness.getBusinessRename(),
//                    tbBusiness.getBusinessPhone());
//        }catch (Exception e){
//            e.printStackTrace();
//
//        }
//        //转换成json格式
//        JSONArray objects = JSONObject.parseArray(result);
//        JSONObject resp = objects.getJSONObject(Integer.parseInt("resp"));
//        //取出状态码
//        Integer code = resp.getInteger("code");
//        if(code!=200){
//            return new Result(false,"0","执行失败");
//        }
//        return new Result(true,"1","执行成功");
//    }
}
